package com.hezongxi.service;

import com.hezongxi.controller.UserController;
import com.hezongxi.dao.UserDao;
import com.hezongxi.entity.User;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.*;


@Service
@Transactional
public class UserServiceImpl implements UserSevice {
    @Autowired
    private UserDao userDao;

    private long time = 1000*60*60*24;
    private String signature = "admin";
//登录服务
    @Override
    public User login(User userDB) {
        if (userDao.findByUserName(userDB.getUsername(), userDB.getPassword()) != null) {
            System.out.println("登录成功！数据库查到用户信息："+userDao.findByUserName(userDB.getUsername(),userDB.getPassword()));
            return userDB;
        }else {
               throw new RuntimeException("用户名或密码错误！");
           }
        }
//查找所有用户
    @Override
    public List<User> findAllUser() {
        List<User> list = userDao.findAllUser();
        list.forEach(user-> System.out.println(user));
        return list;
    }

    @Override
    public void addUser(User user) {
        user.setRegisterTime(new Date());
        userDao.addUser(user);
    }

    @Override
    public void deleteUser(String id) {
        userDao.deleteUser(id);
    }
}





